package com.wkq.dao;

import com.wkq.domain.Permission;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface IPermissionDao {

//    根据角色id查询出该角色拥有的资源权限
    @Select(" select p.id, p.permissionName, p.url " +
            "from permission as p right join role_permission as r " +
            "on p.id = r.permissionId where r.roleId = #{roleId} ")
    public List<Permission> findAllByRoleId (String roleId);

//    根据角色id查询出该角色没有拥有的资源权限
    @Select(" select p.id, p.permissionName, p.url " +
            "from permission as p left join " +
            "(select permissionId, roleId from role_permission where roleId = #{roleId}) as r " +
            "on p.id = r.permissionId where r.roleId is null ")
    public List<Permission> findOtherPermission (String roleId);

    @Select(" select id, permissionName, url from permission ")
    public List<Permission> findAll ();

    @Insert(" insert into permission (permissionName, url) values (#{permissionName}, #{url}) ")
    public int save (Permission permission);
}
